import { _Array } from './Array'
import { LinkedList } from './LinkedList'


export class ArrayStack {
    constructor(capacity) {
        this.array = new _Array(capacity)
    }

    push(e) { // O(1)
        this.array.addLast(e)
    }

    pop() { // O(1)
        return this.array.removeLast()
    }

    peek() { // O(1)
        return this.array.getLast()
    }

    getSize() { // O(1)
        return this.array.getSize()
    }

    isEmpty() { // O(1)
        return this.array.isEmpty()
    }

    getCapacity() {
        return this.array.getCapacity()
    }
}


export class LinkedListStack {
    constructor() {
        this.list = new LinkedList()
    }

    push(e) { // O(1)
        this.list.addFirst(e)
    }

    pop() { // O(1)
        return this.list.removeFirst()
    }

    peek() { // O(1)
        return this.list.getFirst()
    }

    getSize() {
        return this.list.getSize()
    }

    isEmpty() {
        return this.list.isEmpty()
    }

}